/**
 * Copyright 2010 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package saig.engine.models;

import java.awt.Graphics;

import saig.engine.Context;
import saig.engine.models.enums.ModelType;
import saig.engine.resources.ImageLoader;

/**
 * TODO comment
 * @author Adam
 * @version $Id$
 * 
 * Created on Aug 23, 2010 at 9:25:36 PM 
 */
public class Flag extends Model {

	/**
	 * Constructs a Finishing Flag.
	 * @param context The context.
	 * @param type The model type.
	 */
	public Flag(Context context) {
		super(context, ModelType.FLAG);
		frames = ImageLoader.getInstance().getSprites("flag.png", 16, 16);
	}

	/**
	 * {@inheritDoc}
	 * @see saig.engine.models.Model#getHeight()
	 */
	@Override
	public int getHeight() {
		return 144;
	}

	/**
	 * {@inheritDoc}
	 * @see saig.engine.models.Model#getWidth()
	 */
	@Override
	public int getWidth() {
		return 48;
	}

	/**
	 * {@inheritDoc}
	 * @see saig.engine.models.Model#performUpdate()
	 */
	@Override
	public void performUpdate() {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 * @see saig.engine.models.Model#doRender(java.awt.Graphics, float, float)
	 */
	@Override
	public void doRender(final Graphics g, final float cameraX, final float cameraY) {
		final int xPos = ((int) (x - cameraX)) - (getWidth() / 2);
		final int yPos = ((int) (y - cameraY)) - getHeight() + 1;
		// Draw top of the flag pole.
		g.drawImage(frames[0].getImage(), xPos, yPos, null);
		g.drawImage(frames[2].getImage(), xPos + 32, yPos, null);
		// Draw the body of the pole.
		for (int i = 16; i < getHeight(); i += 16) {
			g.drawImage(frames[1].getImage(), xPos, yPos + i, null);
			g.drawImage(frames[3].getImage(), xPos + 32, yPos + i, null);
		}
		// TODO calculate y position for the bar.
		final int yBarPos = 50;
		// Draw the flag/bar.
		g.drawImage(frames[4].getImage(), xPos + 8, yPos + yBarPos, null);
		g.drawImage(frames[5].getImage(), xPos + 24, yPos + yBarPos, null);
	}
}
